***This do file creates the analysis for the SSRP P&P paper 

***Run this file from the master do file please!! 

****************SUMMARY STATISTICS***************; 

***Averages for full sample 
sum male age  educ_bach_lower years_experience years_this_school 
***Summary statistics for paper text 
count
codebook school_id
tab el_T_Cmp_subject_teach_Eg
tab el_T_Cmp_subject_teach_Ma


sum el_T_Cmp_Eg_primary_knowledge if el_T_Cmp_subject_teach_Eg==1

sum el_T_Cmp_Ma_primary_knowledge if el_T_Cmp_subject_teach_Ma==1


***Table 1  
**Col 1: just demographics 
reg el_T_Cmp_Eg_pct_scored  male_imp* age_sq_imp* age_imp*  educ_bach_lower_imp* years_experience_imp* years_experience_sq_imp* standard_utkarsh flexible_utkarsh if el_T_Cmp_subject_teach_Eg==1, robust
sum el_T_Cmp_Eg_pct_scored if e(sample)==1 
estadd scalar meaner=r(mean)
eststo A

 

reg el_T_Cmp_Ma_pct_scored   male_imp* age_sq_imp* age_imp*  educ_bach_lower_imp* years_experience_imp* years_experience_sq_imp* standard_utkarsh flexible_utkarsh if el_T_Cmp_subject_teach_Ma==1, robust
sum el_T_Cmp_Ma_pct_scored if e(sample)==1 
estadd scalar meaner=r(mean)
eststo C


estout A  C    using "$outtab/table1_regs_Eg_Ma.tex", style(tex) replace drop(flexible_utkarsh standard_utkarsh _cons male_imp_flag years_experience_imp_flag ) order(male_imp age_imp age_sq_imp educ_bach_lower_imp years_experience_imp years_experience_sq_imp) ///
	 ///
	varlabels(male_imp "Male" age_imp "Age" age_sq_imp "Age-Sq" years_experience_imp "Years Experience" years_experience_sq_imp "Years Experience-Sq" educ_bach_lower_imp "Education: Bachelors or Lower") ///
	nobaselevels noomitted /// //this omits the baselevels of factor variables
	eqlabels(none) collabels(none) mlabels(none) mgroups(none) label ///
	cells("b(fmt(3))" "se(fmt(3)par)")  ///
	stats(N r2 meaner ,  /// 
	labels(`"Observations"' `" \(R^{2}\)"' `"Mean, Dep Var"'  ) fmt(%9.0fc 3 3  )) ///
	prehead("\begin{tabular}{l*{@E}{c}}" ///
	"\toprule" ///
	"  &\multicolumn{1}{c}{\shortstack{ English Score \\ (PCT) }} & \multicolumn{1}{c}{\shortstack{Math Score \\ (PCT)}}  \\" ///
 	"& \multicolumn{1}{c}{(1)}& \multicolumn{1}{c}{(2)} \\")  ///
	posthead("\midrule") ///
	prefoot("\\" "\midrule" "\multicolumn{1}{c}{}\\")   ///
	postfoot("\bottomrule" "\end{tabular}")
		
	cap n estimates clear 
	
preserve
***Table 2 
use "$dat/Teacher_Competency_and_Individual_Student_Score.dta", clear

gen pct_teacher_competency = teacher_competency/100
label var pct_teacher_competency "Content Knowledge"
***Use a consistent sample 

reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_, cluster(unique_teacher_id) a(student_test_score_subject unique_student_id)
gen insample=e(sample)

reghdfe bl_irt_wgt_std_ pct_teacher_competency treatment  if insample==1, cluster(unique_teacher_id) a(student_test_score_subject)

***Panel A: Combined 
reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ standard_utkarsh flexible_utkarsh   if insample==1, cluster(unique_teacher_id) a(student_test_score_subject)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "No" , replace
estadd local student "No" , replace
est store panela_1


reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if insample==1, cluster(unique_teacher_id) a(student_test_score_subject school_id)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "Yes" , replace
estadd local student "No" , replace
est store panela_2

reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if insample==1, cluster(unique_teacher_id) a(student_test_score_subject unique_student_id)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "No" , replace
estadd local student "Yes" , replace
est store panela_3


***Panel B: Control Schools Only 
reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if treatment==0 & insample==1, cluster(unique_teacher_id) a(student_test_score_subject)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "No" , replace
estadd local student "No" , replace
est store panelb_1

reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if treatment==0 & insample==1, cluster(unique_teacher_id) a(student_test_score_subject school_id)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "Yes" , replace
estadd local student "No" , replace
est store panelb_2


reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if treatment==0 & insample==1, cluster(unique_teacher_id) a(student_test_score_subject unique_student_id)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "No" , replace
estadd local student "Yes" , replace
est store panelb_3

***Panel C: Treatment Schools Only 
reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if treatment!=0 & insample==1, cluster(unique_teacher_id) a(student_test_score_subject)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "No" , replace
estadd local student "No" , replace
est store panelc_1

reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if treatment!=0 & insample==1, cluster(unique_teacher_id) a(student_test_score_subject school_id)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "Yes" , replace
estadd local student "No" , replace
est store panelc_2

reghdfe el_irt_wgt_std_ pct_teacher_competency bl_irt_wgt_std_ if treatment!=0 & insample==1, cluster(unique_teacher_id) a(student_test_score_subject unique_student_id)
estadd scalar pval = (2 * ttail(e(df_r), abs(_b[pct_teacher_competency] / _se[pct_teacher_competency]) ) )
scalar N_clust = e(N_clust)
estadd local school "No" , replace
estadd local student "Yes" , replace
est store panelc_3


local titlesc "& \multicolumn{3}{c}{Student Test Scores (SD)}  \\ \textbf{Panel A: All Schools} & (1) & (2)& (3) \\ \hline"

esttab panela_1 panela_2 panela_3 ///
using "$outtab/table2_a.tex", replace ///
cells("b(fmt(3))" "se(fmt(3)par)" "p(par([ ]) fmt(3))") label nonumber booktabs ///
keep(pct_teacher_competency) nostar alignment(c) ///
mlabels(none) collabels(none) posthead("`titlesc'" ) nonotes  frag noobs  stats( N  r2 , labels( `"\# Students"'  `" \(R^{2}\)"'  ) fmt( %9.0fc 3))


local titlesc "\textbf{Panel B: Control Schools }  \\ \hline"
esttab panelb_1 panelb_2 panelb_3 ///
using "$outtab/table2_b.tex", replace ///
 cells("b(fmt(3))" "se(fmt(3)par)" "p(par([ ]) fmt(3))") label nonumber booktabs ///
keep(pct_teacher_competency) nostar alignment(c) ///
mlabels(none) collabels(none) posthead("`titlesc'" ) nonotes  frag noobs stats( N r2, labels( `"\# Students"'  `" \(R^{2}\)"') fmt( %9.0fc  3))


local titlesc "\textbf{Panel C: Treatment Schools } \\ \hline"
esttab panelc_1 panelc_2 panelc_3 ///
using "$outtab/table2_c.tex", replace ///
 cells("b(fmt(3))" "se(fmt(3)par)" "p(par([ ]) fmt(3))") nostar label nonumber booktabs ///
keep(pct_teacher_competency)  alignment(c) ///
mlabels(none) collabels(none) posthead("`titlesc'" ) nonotes  frag noobs stats( N  r2  school student, labels( `"\# Students"'  `" \(R^{2}\)"'  `"School FE"' `"Student FE"'  ) fmt( %9.0fc  3))

restore

